<template>
	<body-wrap :isFlex='true' :showLoading="false">
		<view class="buymain">
			<view class="buyRadiusBox">
				<buy-list :type='1'/>
			</view>
			<mall-order-user-info ref="oMall" v-if="orderInfo.orderType==1"/>
			<service-order-user-info ref="oService" v-else-if="orderInfo.orderType==2"/>
		</view>
		<template v-slot:footer>
			<view class="bbtbox">
				<order-botton @onclick="comfirm" bottomText="确定"/>
			</view>
		</template>
	</body-wrap>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import bodyWrap from "@/components/bodyWrap/index.vue"
	import buyList from '@/components/buyList/buyList.vue'
	import orderBotton from '@/components/orderBotton/orderBotton.vue'
	import {mallOrderUserInfo} from "./components/mallOrderUserInfo.vue"
	import {serviceOrderUserInfo} from "./components/serviceOrderUserInfo.vue"
	import {getShippingCost} from "@/api/index.js"
	export default defineComponent({
		components:{
			bodyWrap,
			buyList,
			orderBotton,
			mallOrderUserInfo,
			serviceOrderUserInfo
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				imgUrlPrefix:getApp().globalData.imgUrlPrefix,
				type:1,
				//orderType:1, // 1为商城订单，2为订餐订单
				orderInfo:computed(()=>store.state.base.orderInfo), 
			})
			
			onMounted(()=>{
				getShippingCost().then(res=>{
					// 保存配送费用
					//store.commit('base/set_orderInfo',{deliveryFee:res.data}) 
					state.orderInfo.deliveryFee = res.data
				})
				console.log("orderInfo:",state.orderInfo)
			})
			
			
			const comfirm = ()=>{
				console.log("orderInfo:",state.orderInfo)
				let checkFlag = false
				if(state.orderInfo.orderType==1){
					checkFlag = proxy.$refs.oMall.checkForm()
				}else if(state.orderInfo.orderType==2){
					checkFlag = proxy.$refs.oService.checkForm()
				}
				
				if(checkFlag){
					uni.navigateTo({
						url:'/pages/order/order'
					})
				}
			}
			
			
			return {
				...toRefs(state),
				comfirm
			}
		}
	})
</script>

<style lang="scss" scoped>
	.buymain{
		padding: 0 30rpx;
		.buyRadiusBox{
			box-sizing: border-box;
			width: 100%;
			background: #fff;
			padding: 30rpx;
			border-radius: 30rpx;
			//box-shadow: 0 0 10rpx #afafaf;
			margin: 0 0 30rpx 0;
			
		}
		
	}
	
	.bbtbox{
		padding: 20rpx 30rpx;
	}
</style>

